<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function fn(N,M){
             return Math.floor(Math.random()*(M-N+1))+N
        }
        let randomNum = fn(1,10)
        console.log(randomNum);
        
       for(let i=1;i<=3;i++) {
            let useInput = +prompt('请输入1~10之间的数字:')
            if(useInput>randomNum){
                alert(`数字猜大了，你还有${3-i}次机会`)
            }else if(useInput<randomNum){
                alert(`数字猜小了，你还有${3-i}次机会`)
            }else{
                alert(`数字猜对了，你还有${3-i}次机会`)
                break
            }
        }

    </script>
</body>
</html>